﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebHoiChoMuaBan.Models;

namespace WebHoiChoMuaBan.Controllers.Helpers
{
    public class NewsProductThumbHelper : HelperBase
    {
        public NewsProductThumb getProductMainThumbById(int ProId)
        {
            try
            {
                return (from n in this.dataContext.NewsProductThumbs
                        where n.NProId == ProId && n.NProThumbIsMain == true
                        select n).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public NewsProductThumb getProductThumbById(int id)
        {
            try 
            {
                return (from n in this.dataContext.NewsProductThumbs
                        where n.NProThumbId == id
                        select n).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        //
        // Insert/Delete Methods
        public void Add(NewsProductThumb newsProductThumb)
        {
            this.dataContext.NewsProductThumbs.InsertOnSubmit(newsProductThumb);
        }

        public void Delete(NewsProductThumb newsProduct)
        {
            this.dataContext.NewsProductThumbs.DeleteOnSubmit(newsProduct);
        }

        //
        // Persistence
        public void Save()
        {
            this.dataContext.SubmitChanges();
        }
    }
}